<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('component_categories', function (Blueprint $table) {
            $table->id();
            $table->string('title')->unique();
            $table->string('slug')->unique();
            $table->foreignId('parent_id')->nullable()->constrained('component_categories')->onDelete('cascade');
            $table->string('description')->nullable();
            $table->timestamps();
        });

        DB::table('component_categories')->insert([
            [
                'title' => 'Buttons',
                'slug' => 'buttons',
                'description' => 'Component',
            ],
            [
                'title' => 'Cards',
                'slug' => 'cards',
                'description' => 'Component',
            ],
            [
                'title' => 'Forms',
                'slug' => 'forms',
                'description' => 'Component',
            ],
        ]);
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('component_categories');
    }
};
